/**
 *
 */
package cn.dw.sg.mapper.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import cn.dw.sg.domain.Authority;
import cn.dw.sg.mapper.AuthorityMapper;
import cn.dw.sg.utils.JdbcUtil;

/**
 * @author aubrey
 * @date  下午2:43:16
 * 
 */
@Component("auMapper")
public class AuthorityMapperImpl implements AuthorityMapper {

	
	
	

	public void add(Authority authority) {
		
		//jdbc方式
		String sql = "insert into authority(role_id,menu_id) values("+
				authority.getRoleId() +","+authority.getMenuId()+")";
		JdbcUtil.excute(sql);
	}


	public void update(Authority authority) {
		//jdbc方式
		String sql = "update authority  set role_id="+ authority.getRoleId() 
		+", menu_id="+authority.getMenuId()+" where id = " + authority.getId();
		JdbcUtil.excute(sql);
	}


	public void delete(int id) {
		//jdbc方式
		String sql = "delete from authority where id = " + id;
		JdbcUtil.excute(sql);
	}


	public List<Authority> query(Authority authority) {
		String sql = "select id ,role_id as roleId , menu_id as menuId ,notes from authority ";
		List<Object> results = JdbcUtil.excuteQuery(sql,Authority.class);
		List<Authority> lists = new ArrayList<>();
		for(Object b : results) {
			Authority temp = (Authority)b;
			lists.add(temp);
		}
		return lists;
	}

}
